<template>
  <v-card>
      <v-flex xs12 sm10>
        <v-tree url="/info/category/list"
                :isEdit="isEdit"
                @handleAdd="handleAdd"
                @handleEdit="handleEdit"
                @handleDelete="handleDelete"
                @handleClick="handleClick"
        />
      </v-flex>

  </v-card>
</template>

<script>
  // 导入自定义的表单组件
  import CategoryForm from './CategoryForm'
  export default {
    name: "category",
    data() {
      return {
        isEdit:true,
        category:{
          id : 0,
          name: "",
          parentId: 1,
          isParent: false,
          sort: 1
        }
      }
    },

    methods: {
      handleAdd(node) {
        debugger;
        this.category = node;
       /* this.$http({
          method: this.isEdit ? 'put' : 'post',
          url: '/info/category',
          data: node,//this.$qs.stringify(params)
        }).then(() => {
          // 关闭窗口
          this.$emit("close");
          this.$message.success("保存成功！");
        })
          .catch(() => {
            this.$message.error("保存失败！");
          });*/
      },
      handleEdit(id, name) {
        this.category.id = id;
        this.category.name = name;
       //console.log("edit... id: " + id + ", name: " + name)
        this.$http({
          method: 'post',
          url: '/info/category',
          data: this.category,//this.$qs.stringify(params)
        }).then(() => {
          // 关闭窗口
          this.$emit("close");
          this.$message.success("保存成功！");
        })
          .catch(() => {
            this.$message.error("保存失败！");
          });
      },
      handleDelete(id) {
        this.$http.delete("/info/category/delete?id=" + id,).then(() => {
          debugger;
          this.$message.success("删除成功！");
          //this.getDataFromApi();
        })
      },
      handleClick(node) {
        console.log(node)
      }
    },
    components:{
      CategoryForm: CategoryForm
    }
  };
</script>

<style scoped>

</style>
